@extends('admin.index.layout')

@section('title', $title)

@section('content')
    
        <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                订单管理
                <small>订单列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">订单管理</a></li>
                <li class="active">订单列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">


                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">查看订单列表</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <form action="{{ url('/admin/user/index') }}">
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="input-group margin">
                                            <input type="text" class="form-control" value="{{ $request['keywords'] or '' }}" name="keywords">
                                            <span class="input-group-btn">
                                              <button class="btn btn-info btn-flat" type="submit">搜索</button>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="col-md-2  col-md-offset-6">
                                        <div class="form-group">
                                        
                                            <label>Select</label>
                                            <select name="num" class="form-control">
                                                <option
                                                @if(!empty($request['num']) 
                                                && $request['num'] == 10)
                                                    selected = "selected"
                                                @endif
                                                >10</option>
                                                <option
                                                @if(!empty($request['num']) 
                                                && $request['num'] == 25)
                                                    selected = "selected"
                                                @endif
                                                >25</option>
                                                <option
                                                @if(!empty($request['num']) 
                                                && $request['num'] == 50)
                                                    selected = "selected"
                                                @endif
                                                >50</option>
                                                <option
                                                @if(!empty($request['num']) 
                                                && $request['num'] == 100)
                                                    selected = "selected"
                                                @endif
                                                >100</option>
                                            </select>

                                        </div>
                                    </div>
                                </div>
                            </form>
                                
                            <table id="example1" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>订单号</th>
                                    <th>商品名</th>
                                    <th>用户名</th>
                                    <th>订单状态</th>
                                    <!-- <th>有无发票</th> -->
                                    <th>配送状态</th>
                                    <th>付款状态</th>
                                    <!-- <th>配送方式</th>
                                    <th>支付方式</th> -->
                                    <!-- <th>下单时间</th>
                                    <th>确认时间</th>
                                    <th>支付时间</th>
                                    <th>发货时间</th> -->
                                    <!-- <th>配送信息id</th> -->
                                    <th>用户备注</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                @foreach($data as $u)
                                <tr>
                                    <td class="ids">{{$u -> id }}</td>
                                    <td class="order_num">{{$u -> order_num }}</td>
                                    <td class="gname">{{$u -> gname }}</td>
                                    <td class="uname">{{$u -> uname }}</td>
                                    <td class="order_status">{{$u -> order_status==0 ? '待发货': ($u -> order_status==1 ? '已发货':'已完成') }}</td>
                                    
                                    <td class="shipping_status">{{$u -> shipping_status? '已送达':'配送中' }}</td>
                                    <td class="pay_status">{{$u -> pay_status ? '已付款':'待付款' }}</td>
                                    <td class="postscript">{{$u -> postscript }}</td>
                                    
                                    
                                    <td><a href="{{url('/admin/order/detail')}}/{{$u ->order_num}}"><i class="fa fa-fw fa-pencil"></i></a> &nbsp; <a href="{{url('/admin/order/del')}}/{{$u -> id}}"><i class="fa fa-fw fa-remove"></i></a></td>
                                </tr>
                                @endforeach
                                </tbody>
                            </table>
                            {!! $data ->appends($request) -> render() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->

    <script type="text/javascript">
        window.onload = function()
        {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('.order_status').on('click', function()
            {
                //获取当前对象
                var t = $(this);
                console.log(t.html());
                var id = $(this).parent().find('.ids').html();
                // alert(id);
                $.ajax({
                    type:"GET",
                    url:"{{ asset('admin/order/ajax') }}",
                    data:{id:id},
                    success:function(data)
                    {
                        // alert(data);
                       if(data == 0)
                       {
                            // alert(0)
                            t.html('待发货');
                       }else if(data == 1)
                       {
                            // alert(1)
                            t.html('已发货');
                       }else if(data == 2)
                       {
                            t.html('已完成');
                       }
                    },
                    error:function()
                    {
                        alert('异常');
                    }
                });
                console.log(t.html());
            });

        
        }
    </script>
    


@endsection